﻿using System;
using System.Diagnostics.Contracts;
using CardPlay.Model.ActionModel;

namespace CardPlay.Model.GameModel.Actions
{
    internal class HistoryOfPlays : ActionHistory
    {
        private readonly IGame _game;

        public Action<StateOfPlay> HistoryChanged;

        public HistoryOfPlays(IGame game)
        {
            Contract.Requires<ArgumentNullException>(game != null, "game");
            _game = game;
        }

        #region Implementation

        protected override bool IsChangePermitted
        {
            get { return _game.IsPlayable(); }
        }

        protected override object CreateSnapshot()
        {
            return _game.StateOfPlay;
        }

        protected override void OnStateChanged(object priorState)
        {
            if (HistoryChanged != null) HistoryChanged((StateOfPlay)priorState);
        }

        #endregion
    }
}